﻿using FileZillaConfig.Helpers;
using System;

namespace FileZillaConfig.Types
{
    public class Password
    {
        private string _password = "";


        /// <summary>
        /// Set new password and encode with MD5 checksum
        /// </summary>
        /// <param name="plainPassword">Minimum length is 6 characters</param>
        public void SetPassword(string plainPassword)
        {
            if (String.IsNullOrEmpty(plainPassword) || plainPassword.Length >= 6)
            {
                this._password = MD5Hash.CalculateMD5Hash(plainPassword);
            }
            else
            {
                throw new System.Exception("Minimum password length is 6 characters.");
            }
            
        }

        /// <summary>
        /// Store password without encoding. String should be MD5 checksum.
        /// </summary>
        /// <param name="hashedPassword">MD5 checksum</param>
        public void storePassword(string hashedPassword)
        {
            this._password = hashedPassword;
        }

        /// <summary>
        /// Set password to none
        /// </summary>
        public void Clear()
        {
            this._password = "";
        }

        /// <summary>
        /// Get current password
        /// </summary>
        public string Get
        {
            get
            {
                return this._password;
            }
        }

    }
}
